package com.itheima.methodreference;

import java.util.Arrays;

public class Demo2 {

    public static void main(String[] args) {

        //实例方法引用
        //格式：对象名::方法名
        test();

    }

    public static void test() {

        Student[] students = new Student[5];
        students[0] = new Student("张三", 18, "男", 1.81);
        students[1] = new Student("李四", 14, "女", 1.72);
        students[2] = new Student("王五", 20, "男", 1.83);
        students[3] = new Student("赵六", 22, "女", 1.74);
        students[4] = new Student("孙七", 12, "男", 1.75);

        Student s = new Student();
        //Arrays.sort(students, (o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight()));
        //Arrays.sort(students, (o1, o2) -> s.compareByHeight(o1, o2));

        //如果这个Lambda表达式里只是通过对象名调用一个实例方法，并且"->"前后参数的形式一致，就可以使用实例方法引用
        Arrays.sort(students, s::compareByHeight);

        for (Student student : students) {
            System.out.println(student);
        }
    }
}
